<template>
  <el-form ref="formRef" style="max-width: 600px" :inline="true" :model="formInline" class="demo-form-inline">
    <el-form-item label="职位名称：" prop="name" style=" width:250px;" :rules="[{
      required: true,
      message: '请输入职位名称',
      trigger: 'blur'
    }]">
      <el-input v-model="formInline.name" placeholder="请输入职位名称" clearable />
    </el-form-item>
    <el-form-item label="详细描述：" prop="remark" style=" width:250px;" required :rules="[{
      required: true,
      message: '请输入详细描述：',
      trigger: 'blur'
    }]">
      <el-input v-model="formInline.remark" placeholder="请输入详细描述" clearable />
    </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit(formRef)">提交</el-button>
      </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { ApiPost } from '@/utils/Axios';
import { ElNotification, FormInstance } from 'element-plus'
import { reactive, ref } from 'vue'
const formRef = ref<FormInstance>()
const formInline = reactive({
  name: '',
  remark: ''
})

const onSubmit = (formEl:FormInstance|undefined) => {
  formEl.validate(val=>{
    if(val){
      ApiPost('/jobInf/add',formInline).then(res=>{
        if(res.code === 200){
          ElNotification({
            title: '添加成功',
            type:'success',
            duration: 2000,
            showClose:false 
          })
        }else{
          ElNotification({
            title: '添加失败',
            message: res.msg,
            type: 'error',
            duration: 2000,
            showClose:false
          })
        }
      }).catch(err=>{
        console.log(err)
      })
    }
  })
}
</script>

<style></style>